<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="订单号" prop="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发布类型">
            <el-input v-model="form.attach" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发布类型对应的id">
            <el-input v-model="form.attachId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发布时间对应的id">
            <el-input v-model="form.publishMoneyId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单信息">
            <el-input v-model="form.body" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="总支付金额（单位：分）">
            <el-input v-model="form.totalFee" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="交易类型">
            <el-input v-model="form.tradeType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发起支付ip">
            <el-input v-model="form.spbillCreateIp" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单状态0:待支付；-1.支付失败，1支付成功">
            <el-input v-model="form.status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="微信支付订单号">
            <el-input v-model="form.transactionId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付完成时间">
            <el-input v-model="form.endTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建人">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新人">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="订单号" />
        <el-table-column prop="userId" label="用户id" />
        <el-table-column prop="attach" label="发布类型" />
        <el-table-column prop="attachId" label="发布类型对应的id" />
        <el-table-column prop="publishMoneyId" label="发布时间对应的id" />
        <el-table-column prop="body" label="订单信息" />
        <el-table-column prop="totalFee" label="总支付金额（单位：分）" />
        <el-table-column prop="tradeType" label="交易类型" />
        <el-table-column prop="spbillCreateIp" label="发起支付ip" />
        <el-table-column prop="status" label="订单状态0:待支付；-1.支付失败，1支付成功" />
        <el-table-column prop="transactionId" label="微信支付订单号" />
        <el-table-column prop="endTime" label="支付完成时间" />
        <el-table-column prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column v-permission="['admin','wechatOrder:edit','wechatOrder:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWechatOrder from '@/api/wechatOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, userId: null, attach: null, attachId: null, publishMoneyId: null, body: null, totalFee: null, tradeType: null, spbillCreateIp: null, status: null, transactionId: null, endTime: null, createTime: null, updateTime: null, createBy: null, updateBy: null }
export default {
  name: 'WechatOrder',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '微信支付订单', url: 'api/wechatOrder', sort: 'id,desc', crudMethod: { ...crudWechatOrder }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'wechatOrder:add'],
        edit: ['admin', 'wechatOrder:edit'],
        del: ['admin', 'wechatOrder:del']
      },
      rules: {
        id: [
          { required: true, message: '订单号不能为空', trigger: 'blur' }
        ]
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
